/*
 * @(#)ReadProperty.java		       Project:Tools
 * Date:2012-12-10
 *
 * Copyright (c) 2011 CFuture09, Institute of Software, 
 * Guangdong Ocean University, Zhanjiang, GuangDong, China.
 * All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.sinaapp.msdxblog.tools.androidtype;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.Iterator;

import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;

/**
 * @author Geek_Soledad (66704238@51uc.com)
 */
public class ReadProperty {
	public static void main(String[] args) {
		PropertiesConfiguration properties = new PropertiesConfiguration();
		try {
			properties.load(new InputStreamReader(new FileInputStream("assets/build.prop")));
//			properties.load(new FileInputStream("assets/build.prop"));
			properties.setProperty("ro.build.date",
					"2012年 04月 13日 星期五 09:40:13 CST");
//			System.out.println(new String(properties.getString("ro.build.date").getBytes("ISO8859-1"), "UTF8"));
//			String value = new String(properties.getString("ro.build.date").getBytes("ISO8859-1"), "UTF8");
//			properties.setProperty("ro.build.date", value);
			properties.setProperty("ro.product.model", "MI-ONE Plus");
			properties.setProperty("ro.product.manufacturer", "大米");
			Iterator<String> iterators = properties.getKeys();
			while (iterators.hasNext()) {
				String key = iterators.next();
				String v = properties.getString(key);
				System.out.println(key + "=" + v);
			}
			properties.save(new FileOutputStream("assets/build1.prop"));
//			properties.save(new FileOutputStream("assets/build1.prop"));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (ConfigurationException e) {
			e.printStackTrace();
		} 

		try {
			OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(new File("assets/a.txt")));
			writer.write("这是一个中文");
			writer.flush();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
